﻿using System;
using Resources;
using Yglu.BusinessLayer;

namespace Yglu.WebAdmin
{
	public partial class Default_aspx : BasePage
	{
		#region Main methods

		protected void Page_Load(object sender, EventArgs e)
		{
			if (!IsPostBack)
			{
				TxtUserPhone.Text = SessionManager.LoggedUser.Phone;
			}
		}

		#endregion

		#region Update my account

		protected void ButUpdateUser_Click(Object sender, EventArgs e)
		{
			if (TxtPassword.Text.Length > 3 && TxtPassword.Text == TxtPasswordConfirm.Text)
			{
				SessionManager.LoggedUser.PasswordHash = BusinessLayer.Entities.User.GetPasswordHash(SessionManager.LoggedUser.Store.Id, TxtPassword.Text.Trim());
			}

			try
			{
				DataAccess.User_Upsert(SessionManager.LoggedUser);

				ClientScript.RegisterStartupScript(typeof(String), "UserSaved", "YgluTopAlert('" + Messages.ConfirmationDataSaved + "', true);", true);
			}
			catch (Exception ex)
			{
				Master.SetError(ex, Messages.ErrorCouldNotSaveData);
			}
		}

		#endregion
	}
}